using System;
using System.Collections.Generic;
using System.Linq;
using BLToolkit.Data;
using BLToolkit.Data.Linq;
using dbvc.data;

namespace dbvc.Queries
{
    public class VersionQuery: GenericQuery<db_version>
    {
        private static readonly Func<DAA, int[], IOrderedQueryable<db_version>> cGetVers = CompiledQuery.Compile((DAA db, int[] vers) =>
            db.GetTable<db_version>().Where(v => vers.Contains(v.id)).OrderBy(v => v.on_date));

        private static readonly Func<DAA, int, IOrderedQueryable<db_version>> cGetProjVers = CompiledQuery.Compile((DAA db, int pid) =>
            db.GetTable<db_version>().Where(v => v.id_project == pid).OrderBy(v => v.on_date));

        public static IList<db_version> GetVersions(int[] ids)
        {
            using (var db = new DAA())
            {
                return cGetVers(db, ids).ToList();
            }
        }

        public static IList<db_version> GetVersions(int prjId)
        {
            using (var db = new DAA())
            {
                return cGetProjVers(db, prjId).ToList();
            }
        }
    }
}